<template>
  <div class="home-container">
    <p class="seg-title">el-input</p>
    <el-input>32</el-input>
    <p class="seg-title">金额输入框</p>
    <lc-input-among-money class="lc-input-among-money" v-model="inputMoney" :clearable="false" placeholder="请输入" :disabled="false"
      :precisionValue="2" :templateType="{ type: 'prefix', value: '$' }">
    </lc-input-among-money>
    <p class="seg-title">文本域</p>
    <lc-textarea
        v-model="textarea"
        :clearable="true"
        :disabled="false"
        :configs="textareaConfigs"
      ></lc-textarea>
      <p class="seg-title">上传</p>
      <lc-upload class="lc-file" v-model="file" :drag="false" :showFileList="true" method="get" :data="{}">
        <el-button class="lc-button" type="primary"> 点击上传 </el-button>
      </lc-upload>
      <p class="seg-title">单选放大镜</p>
      <lc-magnifier-single
      v-model="magnifierSingle"
      :tableConfig="tableConfig"
      :valueKey="valueKey"
      :tableData="tableData"
      :showDialog="showDialog"
      :paginationConfig="paginationConfig"
      @changeDialog="changeDialog"
      @currentPageChange="handleCurrentPage"
    >
      <template v-slot:searchBar>
        <el-form
          :model="form"
          label-width="auto"
          style="max-width: 600px; margin-top: 10px; display: flex"
        >
          <el-form-item label="名称" style="margin-right: 30px">
            <el-input
              v-model="form.name"
              clearable
              @keyup.enter="handleSearch"
            />
          </el-form-item>
          <el-form-item label="地址">
            <el-input
              v-model="form.address"
              clearable
              @keyup.enter="handleSearch"
            />
          </el-form-item>
        </el-form>
      </template>
      <template v-slot:infoBar>
        <div class="info" style="display: flex">
          <p style="margin-right: 50px">机构代码：1000121</p>
          <p>机构名称：中国农业银行有限公司</p>
        </div>
      </template>
      <template v-slot:table>
        <!-- 引用封装的lc-table类型组件 -->
        <el-table
          :data="tableData"
          style="width: 100%; height: 400px; overflow-y: scroll"
          @cell-dblclick="doubleClick"
        >
          <el-table-column
            v-for="item in tableConfig"
            :key="item.label"
            :prop="item.prop"
            :label="item.label"
            :width="item.width"
          />
        </el-table>
        <el-pagination
          background
          v-model:current-page="paginationConfig.currentPage"
          v-model:page-size="paginationConfig.pageSize"
          layout="total, prev, pager, next"
          :total="paginationConfig.total"
          @current-change="handleCurrentPage"
        />
      </template>
    </lc-magnifier-single>
  </div>
</template>

<script lang="ts" setup>
import { ref, reactive } from 'vue'

// 金额输入框
const inputMoney = ref(0)


// 上传
const file = ref([])

// 文本域
const textarea = ref()
const textareaConfigs = ref({
  maxlength: '200',
  minlength: '',
  rows: '3',
  autosize: false,
  showWordLimit: true,
  placeholder: '请输入内容'
});

// 单选放大镜
const valueKey = ref();
const showDialog = ref();
const magnifierSingle = ref('');
const tableConfig = ref();
const paginationConfig = { currentPage: 2, total: 900, pageSize: 10  };
const tableData = ref();
const form = reactive({
  name: '',
  address: ''
});

tableConfig.value = [
  {
    prop: 'date',
    label: '时间'
  },
  {
    prop: 'name',
    label: '名称',
    width: '180'
  },
  {
    prop: 'address',
    label: '地址'
  }
];

tableData.value = [
  {
    date: '2016-05-03',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles'
  },
  {
    date: '2016-05-02',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles'
  }
];

const doubleClick = (val: any) => {
  if (valueKey.value) {
    magnifierSingle.value = val[valueKey.value];
  } else {
    // 做数据处理
    magnifierSingle.value = val.date;
  }
  changeDialog(false);
};

const changeDialog = (val: any) => {
  showDialog.value = val;
};

const handleSearch = () => {
  // 获取搜索条数据
  console.log("form", form);
  // 获取table数据
  tableData.value = [
    {
      date: "2020-01-03",
      name: "Jerry",
      address: "No. 119",
    },
  ];
  // 获取当前页Table数据项 总数
  paginationConfig.total = 800;
};

const handleCurrentPage = (val: any) => {
  console.log("当前页数：", val);
  paginationConfig.currentPage = val;
  // 获取当前页Table数据
  tableData.value = [
    {
      date: "2021-12-03",
      name: "Zoe",
      address: "No. 111,",
    },
  ];
  // 获取当前页Table数据项 总数
  paginationConfig.total = 600;
};


</script>

<style lang="css" scoped>
.home-container {
  margin-right: 0 auto;
  padding: 20px;

}
.seg-title {
  margin-top: 20px;
  padding-top: 10px;
  border-top: 1px dashed #eee;
  font-size: 16px;
  font-weight: 600;
}
</style>
